🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / feature / node / src / commonMain / kotlin / org / meshtastic / feature / node / metrics / HardwareModelExtensions.kt
Displaying Raw • Download
feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/metrics/HardwareModelExtensions.kt 520fa717a938fd84682403b41f57d9f7e1ef49ef (520fa717) Text, 1.62 KB
T8b949e/*
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.node.metrics
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787org.meshtastic.proto.HardwareModel
T8b949e/**
* Safely extracts the hardware model number from a HardwareModel enum.
*
* This function handles unknown enum values gracefully by catching IllegalArgumentException and returning a fallback
* value. This prevents crashes when the app receives data from devices with hardware models not yet defined in the
* current protobuf version.
*
* @param fallbackValue The value to return if the enum is unknown (defaults to 0 for UNSET)
* @return The hardware model number, or the fallback value if the enum is unknown
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffdetekt:SwallowedExceptionTa5d6ff"Tb4b4b4)
Tff7b72fun Te6edf3HardwareModelTb4b4b4.Td2a8ffsafeNumberTb4b4b4(Te6edf3fallbackValueTb4b4b4: Tffa657Int Tff7b72= Tff7b72-T79c0ff1Tb4b4b4)Tb4b4b4: Tffa657Int Tff7b72= Tff7b72try Tb4b4b4{
Tff7b72thisTb4b4b4.Te6edf3value
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3IllegalArgumentExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3w Tb4b4b4{ Ta5d6ff"Ta5d6ffUnknown hardware model enum value: Tffd700$Te6edf3thisTa5d6ff, using fallback value: Tffd700$Te6edf3fallbackValueTa5d6ff" Tb4b4b4}
Te6edf3fallbackValue
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.04s